﻿using System;
using MaLu.Common;
using MaLu.Data;
using System.Data;

namespace MaluJg.web.StatsIn
{
    public partial class SDetail : SPage
    {
        
        protected int RecordID
        {
            get
            {
                int gd = 0;
                if (Request["ID"] != null)
                {
                    int.TryParse(Request["ID"] ?? "0", out gd);

                }
                else
                {
                    if (ViewState["ID"] != null)
                        gd = (int)ViewState["ID"];


                }
                if (ViewState["ID"] == null)
                    ViewState["ID"] = gd;
                return gd;
            }
            set
            {
                ViewState["ID"] = value;
            }

        }
         protected string SType = string.Empty;
        protected void Page_Load(object sender, EventArgs e)
        {
            this.Title = "扶持资金详细清单";
            this.UseTabber = true;
            SType = Request["type"] ?? "fbooth";
            if (!IsPostBack)
            {
               BindData();
            }
        }
        private void BindData()
        {
            uFertilizer1.Visible = false;
            uBooth1.Visible = false;
            uCold1.Visible = false;
            uGreen1.Visible = false;
            uMembrane1.Visible = false;
            uPackage1.Visible = false;
            switch (SType)
            {
                case "fhuafei":
                    uFertilizer1.Visible = true;
                    uFertilizer1.LoadData(); break;
                case "fbooth":
                    uBooth1.Visible = true;
                    uBooth1.LoadData(); break;
                case "fcold":
                    uCold1.Visible = true;
                    uCold1.LoadData(); break;
                case "fgreen":
                    uGreen1.Visible = true;
                    uGreen1.LoadData(); break;

                case "fmembrane":
                    uMembrane1.Visible = true;
                    uMembrane1.LoadData(); break;
                case "fpackage":
                    uPackage1.Visible = true;
                    uPackage1.LoadData(); break;
                default: break;

            }


        }
        protected void lbtnDelete_Click(object sender, EventArgs e)
        {
           

            string table = "FBoothDetails";
            if (SType == "fhuafei")
            {
                table = "FFertilizerDetails";
            }
            if (SType == "fcold")
            {
                table = "FColdStorageDetails";
            }
            if (SType == "fgreen")
            {
                table = "FGreenHouseDetails";
            }
            if (SType == "fmembrane")
            {
                table = "FMembraneDetails";
            }
            if (SType == "fpackage")
            {
                table = "FPackageDetails";
            }
            string sql = string.Format("delete from [{0}] where id ='{1}'",table, RecordID);
            SqlHelper.Instance.ExecuteNonQuery(Provider, sql);
            ClientScript.RegisterStartupScript(this.GetType(), "Delete", "<script>parent.location.href = parent.location.href</script>");
        }

    }
}
